package com.qf.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.InvocationTargetException;

/**
 * 创建者: QF-SUN
 * 创建时间: 2023/4/18 10:04
 * 描述:
 */
public class MyAroundAdvice implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        try {
            System.out.println("开启事务");
            //执行目标对象， 返回目标对象对象的返回值
            Object result = invocation.proceed();
            System.out.println("提交事务");
            return result;
        } catch (Exception e) {
            System.out.println("异常：回滚事务");
            e.printStackTrace();

        } finally {
            System.out.println("最终通知: 释放资源");
        }

        return null;
    }
}
